package yawning.mew.bear;

import yawning.mew.ProcEffect.Trigger;
import yawning.mew.sim.SimulationAction;

public class PotionAction implements SimulationAction {
	BearThreatSimulator mState;
	boolean mUsed;
	boolean mUsedPrePotion;
	double mCooldownExpireTime;

	PotionAction(BearThreatSimulator state) {
		mState = state;
		mUsed = false;
	}

	@Override
	public double perform() {
		if (!mState.mHavePotion || mUsed || mCooldownExpireTime > mState.mSimEngine.getSimTime()) return SimulationAction.ACTION_FAIL;

		mCooldownExpireTime = mState.mSimEngine.getSimTime() + 120; // Potion cooldown is always 120 sec.
		mState.mSimEngine.triggerProc(null, Trigger.POTION);
		if (!mState.isInCombat() && mState.mPrePotion) mUsedPrePotion = true;
		if (!mState.mPrePotion || mState.isInCombat()) mUsed = true;

		// This is handled by the generic proc code.
//		if (mState.mIsLogging) mState.mLog.log("Potion\n");

		return 0.0;
	}

	public boolean canPotion() {
		if (!mState.isInCombat() && mState.mPrePotion && !mUsedPrePotion) return true;

		return (mState.mHavePotion && !mUsed && mCooldownExpireTime < mState.mSimEngine.getSimTime());
	}
}
